package com.xinchen.all.ui.activity

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.location.Location
import android.location.LocationListener
import android.os.Bundle
import android.provider.Settings
import android.widget.Button
import androidx.activity.result.contract.ActivityResultContract
import com.maple.base.base.BaseActivity
import com.maple.utils.util.LogUtils
import com.xinchen.all.R

class HomeActivity : BaseActivity() {
    private var btnPermission: Button? = null
    private var btnBluetooth: Button? = null
    private var btnLocation: Button? = null



    override fun getLayoutId(): Int = R.layout.activity_home


    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        btnPermission = findViewById(R.id.btn_permission)
        btnPermission?.setOnClickListener {

        }

        btnBluetooth = findViewById(R.id.btn_bluetooth)
        btnBluetooth?.setOnClickListener {
//            onStartActivity(BluetoothActivity::class.java)
            onStartActivity(Bluetooth2Activity::class.java)
        }

        btnLocation = findViewById(R.id.btn_location)
        btnLocation?.setOnClickListener {
            onStartActivity(LocationActivity::class.java)
        }


    }

    override fun initData(savedInstanceState: Bundle?) {

    }


    private val launcherProviderResult = registerForActivityResult(object :
        ActivityResultContract<Unit, Boolean>() {
        override fun createIntent(context: Context, input: Unit): Intent {
            return Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
        }

        override fun parseResult(resultCode: Int, intent: Intent?): Boolean {
            return resultCode == Activity.RESULT_OK
        }
    }) {
        if(it != null && it) {

        }
    }

    private val locationListener: LocationListener by lazy {
        object :LocationListener {
            override fun onProviderEnabled(provider: String) {
                super.onProviderEnabled(provider)
                LogUtils.logGGQ("onProviderEnabled")
            }

            override fun onProviderDisabled(provider: String) {
                super.onProviderDisabled(provider)
                LogUtils.logGGQ("onProviderDisabled")
            }
            override fun onLocationChanged(location: Location) {
                val address: String = "${location.longitude}-${location.latitude}"
                LogUtils.logGGQ("===onLocationChanged==>>${address}")
                showToast(address)
            }

        }
    }

}